<template>
  <div style="padding: 10px">
    <div class="gdzlk_content">
      <div class="gdzlk_left">
        <gdzlkFl></gdzlkFl>
      </div>
      <div class="gdzlk_right">
        <div class="right_top">
          <el-breadcrumb separator-class="el-icon-arrow-right" class="right_top_content">
            <el-breadcrumb-item><span class="right_top_item">首页</span></el-breadcrumb-item>
            <el-breadcrumb-item><span class="right_top_item">活动管理</span></el-breadcrumb-item>
            <el-breadcrumb-item><span class="right_top_item">活动列表</span></el-breadcrumb-item>
            <el-breadcrumb-item><span class="right_top_item">活动详情</span></el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="right_bottom">

        </div>
      </div>
    </div>
    <!-- 添加或修改工单资料库对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="父id" prop="pid">
          <el-input v-model="form.pid" placeholder="请输入父id" />
        </el-form-item>
        <el-form-item label="文件名称" prop="wjmc">
          <el-input v-model="form.wjmc" placeholder="请输入文件名称" />
        </el-form-item>
        <el-form-item label="文件路径" prop="wjpath">
          <el-input v-model="form.wjpath" placeholder="请输入文件路径" />
        </el-form-item>
        <el-form-item label="文件类型" prop="wjlx">
          <el-input v-model="form.wjlx" placeholder="请输入文件类型" />
        </el-form-item>
        <el-form-item label="创建人id" prop="createuserid">
          <el-input v-model="form.createuserid" placeholder="请输入创建人id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGdzlk, getGdzlk, delGdzlk, addGdzlk, updateGdzlk } from "@/api/gd/gdzlk";
import gdzlkFl from '@/views/gd/gdzlk/gdzlkFl.vue'
export default {
  name: "Gdzlk",
  components: { gdzlkFl },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单资料库表格数据
      gdzlkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pid: undefined,
        wjmc: undefined,
        wjpath: undefined,
        wjlx: undefined,
        createuserid: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pid: [
          { required: true, message: "父id不能为空", trigger: "blur" }
        ],
        wjmc: [
          { required: true, message: "文件名称不能为空", trigger: "blur" }
        ],
        wjpath: [
          { required: true, message: "文件路径不能为空", trigger: "blur" }
        ],
        wjlx: [
          { required: true, message: "文件类型不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工单资料库列表 */
    getList() {
      this.loading = true;
      listGdzlk(this.queryParams).then(response => {
        this.gdzlkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        pid: undefined,
        wjmc: undefined,
        wjpath: undefined,
        wjlx: undefined,
        createTime: undefined,
        createBy: undefined,
        createuserid: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工单资料库";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getGdzlk(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改工单资料库";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateGdzlk(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addGdzlk(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除工单资料库编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delGdzlk(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('gd/gdzlk/export', {
        ...this.queryParams
      }, `gdzlk_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.gdzlk_content{
  width: 100%;
  display: flex;
  flex-direction: row;
}
.gdzlk_left {
  width: 12%;
  height: 100%;
  margin-right: 2px;
}
.gdzlk_right {
  width: 88%;
}
.right_top {
  width: 100%;
  height: 40px;
  background-color: #F2F6FC;
  border-radius: 5px;
}
.right_top_content {
  line-height: 40px;
  padding-left: 10px;
}
.right_top_item {
  color: black;
  cursor: pointer;
}
.right_top_item:hover {
  font-weight: 800;
}
.right_bottom {
  width: 100%;
  background-color: #00afff;
}
</style>
